// import Vue from 'vue';
import Vuex from 'vuex';
import App from './App.vue'

if (typeof (ELEMENT)!=='undefined') {
  for (let k in ELEMENT) {
    window[k] = global[k] = ELEMENT[k]
  }
}


import promise from 'es6-promise';
import confirm from '@/util/confirm'

import './main.css';

import axiosInstance from '@/lib/request';
import store from '@/store/index';
import DictionaryCode from '@/util/dictionaryCode';
import Filter from '@/util/filter';
import api from '@/api/base.js'

import * as d3 from '@/lib/d3.v4.js'
import qs from 'qs';
import $ from 'jquery'
import '@/util/jquery.form';



window.d3 = global.d3 = d3;
window.$ = global.$ = $;
Vue.prototype.$confirm = confirm;
Vue.prototype.$api = api;
Vue.prototype.$qs = qs;
Vue.prototype.$axiosInstance = axiosInstance;
Vue.config.productionTip = false;
Vue.prototype.$findByName = function(targetName) {
  function f(children, n) {
    for (let i = 0; i < children.length; i++) {
      let c = children[i];
      if (c.$vnode.tag.includes(n)) {
        return c;
      }
      if (c.$children) {
        return  f(c.$children, n);
      }
    }
  }
  return f(this.$root.$children, targetName);
};
Vue.prototype.$findParents = function(targetName) {
  if (!this.$parent) return;
  if (this.$vnode.tag.includes(targetName)) {
    return this
  } else {
    return this.$findParents.call(this.$parent, targetName)
  }
};
Vue.directive('customIcon', {
  bind(el, { value, modifiers }, vnode) {
    el.style.backgroundImage='url('+value+')';
  }
});

Date.prototype.format = function(fmt) { // author: meizz
  var o = {
    'M+': this.getMonth() + 1, // 月份
    'd+': this.getDate(), // 日
    'h+': this.getHours(), // 小时
    'm+': this.getMinutes(), // 分
    's+': this.getSeconds(), // 秒
    'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
    'S': this.getMilliseconds()
    // 毫秒
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 -
            RegExp.$1.length));
  for (var k in o)
    if (new RegExp('(' + k + ')').test(fmt))
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ?
        (o[k]) :
        (('00' + o[k]).substr(('' + o[k]).length)));
  return fmt;
};
promise.polyfill();
Vue.use(Vuex);
Vue.use(DictionaryCode);
Vue.use(Filter);
Vue.prototype.$axiosInstance = axiosInstance;
new Vue({
  store,
  render: h => h(App)
}).$mount('#app-main');
